Dong.defined([ "util.Putil" ], function(_dong, _package) {
	var $Util = null;
	$Util = function(e) {
		var dom = null;
		if ($Util.isString(e)) {
			var domArray = $Util.exec(e);
		} else {
			dom = e;
			var eDomArray = [ dom ];
		}
		return {
			element : function() {
				var o = this;
				if (o.ArrayDom.length == 1) {
					return o.ArrayDom[0];
				} else {
					this;
				}
			},
			ArrayDom : domArray || eDomArray || [],
			html : function(e) {
				if (!!e) {
					this.element().innerHTML = e;
					return this;
				} else {
					return this.element().innerHTML;
				}
			},
			version : "1.0",
			append : function(node) {
				this.element().innerHTML = this.element().innerHTML + node;
				return this;
			},
			bind : function(_n, _fn) {
				if (!!window.attachEvent) {
					_n = "on" + _n;
					this.element().attachEvent(_n, _fn);
				} else {
					this.element().addEventListener(_n, _fn, false);
				}
			},
			unbind : function(_n, _fn) {
				if (this.element().removeEventListener) {
					this.element().removeEventListener(_n, _fn, false);
				} else if (this.element().detachEvent) {
					this.element().detachEvent("on" + _n, _fn);
				}
			},
			css : function(_css) {
				var _style = this.element().style;
				if (!!_css) {
					for ( var _i in _css) {
						_style[_i] = _css[_i];
					}
				}
				return this;
			},
			val : function(_value) {
				if (!!_value) {
					this.element().value = _value;
					return this;
				} else {
					return this.element().value;
				}
			},
			addClass : function(_name) {
				if (!!_name) {
					this.element().className += " " + _name;
				}
				return this;
			},
			// children : function(e) {
			// var domArray = $Util.exec(e, this.element());
			// this.ArrayDom = domArray;
			// return this;
			// },
			each : function(_fn) {
				if (!!_fn) {
					var len = this.length();
					for (var i = 0; i < len; i++) {
						_fn(this.ArrayDom[i], this);
					}
				}
			},
			length : function() {
				return this.ArrayDom.length;
			},
			remove : function() {
				this.element().parentNode.removeChild(this.element());
			},
			parent : function() {
				return this.element().parentNode;
			},
			find : function(e) {
				var domArray = $Util.exec(e, this.element());
				this.ArrayDom = domArray;
				return this;
			}
		};
	};
	$Util.isString = function(e) {
		return ((e instanceof String) || (typeof e).toLowerCase() == 'string');
	};
	$Util.byId = function(_id) {
		return document.getElementById(_id);
	};
	$Util.byName = function(_name) {
		return document.getElementsByName(_name);
	};
	$Util.byClass = function(_class) {
		var rn = new Array();
		if (!!_class) {
			var elements = document.getElementsByTagName("*");
			for (var i = 0; i < elements.length; i++) {
				if (elements[i].className.split(" ").contain(_class)) {
					rn.push(elements[i]);
				}
			}
		}
		return rn;
	};
	$Util.round = function(_a, _b) {
		return Math.round(_a / _b);
	};
	$Util.isArray = function(e) {
		return e instanceof Array;
	};
	$Util.getWindow = function(e) {
		var _body = window.document.body;
		return {
			width : function() {
				return _body.clientWidth;
			},
			height : function() {
				return _body.clientHeight;
			}
		};
	};
	$Util.exists = function(e) {
		if (!e) {
			return false;
		} else {
			return this.isArray(e) ? e.length > 0 : true;
		}
	};
	$Util.remove = function(node) {
		node.parentNode.removeChild(node);
	};
	$Util.getRandom = function(node) {
		var _random = Math.random() + "";
		while (_random.indexOf(".") == -1 || this.exists(this.byId(_random))) {
			_random = Math.random() + "";
		}
		return _random.substring(_random.indexOf('.') + 1);
	};
	$Util.randomColor = function() {
		return '#'
				+ ('00000' + (Math.random() * 0x1000000 << 0).toString(16))
						.slice(-6);
	};
	$Util.exec = function(e, ele) {
		e = e || function(e) {
			e = e.trim();
			return e;
		};
		ele = ele || document;
		var rnDom = new Array();
		if (!!e) {
			if (e.startsWith("<")) {
				var _n = e.substring(1, e.indexOf(">")).trim();
				if (!!_n) {
					if (e.indexOf('[') == -1) {
						var arr = ele.getElementsByTagName(_n);
						var arrlen = arr.length;
						for (var i = 0; i < arrlen; i++) {
							rnDom.push(arr[i]);
						}
					} else {
						var _right = $Util
								.reEmpty(
										e.substring(e.indexOf('[') + 1, e
												.indexOf(']'))).toLowerCase();
						var _key = _right.substring(0, _right.indexOf('='));
						if (_key.toLowerCase() == 'class') {
							_key = "className";
						}
						var _value = _right.substring(_right.indexOf('=') + 1);
						var arr = ele.getElementsByTagName(_n);
						var arrlen = arr.length;
						for (var i = 0; i < arrlen; i++) {
							if (arr[i][_key] == _value) {
								rnDom.push(arr[i]);
							}
						}
					}
					rnDom;
				}
			} else if (e.indexOf('=') != -1) {
				var _key = e.substring(0, e.indexOf("="));
				if (_key.toLowerCase() == 'class') {
					_key = "className";
				}
				_key = _key.trim();
				var _value = e.substring(e.indexOf("=") + 1).trim();
				if (!!_key && !!_value) {
					var arr = ele.getElementsByTagName("*");
					var arrlen = arr.length;
					for (var i = 0; i < arrlen; i++) {
						if (arr[i][_key] == _value) {
							rnDom.push(arr[i]);
						}
					}
					rnDom;
				}
			}
		}
		return rnDom;
	};
	$Util.reEmpty = function(v) {
		return v.replace(/\s/g, "");
	};
	$Util.ajax = function(_json) {
		var _httpRequest = null, _type = _json.type || "GET";
		var _url = _json.url, _async = _json.async || false;
		var _dataType = ("text/" + (_json.dataType || "html")).toLowerCase();
		_dataType = this.reEmpty(_dataType);
		var _data = _json.data || {};
		if (window.XMLHttpRequest) {
			var _xmlHttp = new XMLHttpRequest();
			if (_xmlHttp.overrideMimeType) {
				_xmlHttp.overrideMimeType(_dataType);
			}
			_httpRequest = _xmlHttp;
		} else if (window.ActiveXObject) {
			_httpRequest = new ActiveXObject("MsXml2.XmlHttp");
		} else {
			_httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		var _text = null;
		_httpRequest.onreadystatechange = function() {
			if (_httpRequest.readyState == 4) {
				if (_httpRequest.status == 200 || _httpRequest.status == 304) {
					_text = _httpRequest.responseText;
				} else {
					alert('request error:' + _httpRequest.statusText + ' ('
							+ _httpRequest.status + ')');
					return;
				}
			}
		};
		var _isPost = _type.toUpperCase().trim() == "POST";
		var _param = "";
		for ( var _k in _data) {
			if (!!_k) {
				if (!!_param) {
					_param += "&" + _k + "=" + _data[_k];
				} else {
					_param += _k + "=" + _data[_k];
				}
			}
		}
		if (_isPost) {
			var _right = "";
			var _index = _url.indexOf('?');
			if (_index != -1) {
				_right = _url.substring(_index + 1);
				_url = _url.substring(0, _index);
			}
			_param = !!_param && !!_right ? (_param + "&" + _right) : !_param
					&& !!_right ? _right : !!_param && !_right ? _param : "";
			_httpRequest.open(_type, _url, _async);
			_httpRequest.setRequestHeader("Content-Type",
					"application/x-www-form-urlencoded");
			_httpRequest.send(_param);
		} else {
			if (!!_param) {
				if (_url.indexOf('?') == -1) {
					_url += "?";
				}
				_url += _url.endsWith("?") ? _param : "&" + _param;
			}
			_httpRequest.open(_type, _url, _async);
			_httpRequest.send(null);
		}
		return _dataType == 'text/json' ? eval("(" + _text + ")") : _text;
	};
	$Util.hrefTo = function(url) {
		window.location.href = url;
	};
	$Util.open = function(url) {
		window.open(url);
	};
	_dong.setModule(_package, $Util);
	return _dong;
});